package com.fang.unittest;

import java.io.*;


public class TestDriver02 {
    public static void main(String[] args) throws IOException {
        test04();
    }
    private static void test04(){
        try(BufferedReader bis = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\学习资料\\sayhi.txt")));
            BufferedWriter bos = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\学习资料\\sayhi_04.txt")))) {

            String str = bis.readLine();
            while (str != null){
                bos.write(str);
                bos.write("\n");
                str = bis.readLine();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void test03(){
        try(BufferedReader bis = new BufferedReader(new FileReader("D:\\学习资料\\sayhi.txt"));
           BufferedWriter bos = new BufferedWriter(new FileWriter("D:\\学习资料\\sayhi_03.txt"))) {

            String str = bis.readLine();
            while (str != null){
                bos.write(str);
                bos.newLine();
                str = bis.readLine();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private static void test02() throws IOException {
        Reader is = new FileReader("D:\\学习资料\\sayhi.txt");
        Writer os = new FileWriter("D:\\学习资料\\sayhi_02.txt");
        char[] b = new char[1024];
        int len = is.read(b);

        while(len != -1){
            os.write(b,0,len);
            len = is.read(b);
        }
        is.close();
        os.close();
    }
    private static void test01() throws IOException {
      InputStream is = new FileInputStream("D:\\学习资料\\sayhi.txt");
      OutputStream os = new FileOutputStream("D:\\学习资料\\sayhi_01.txt");
      byte[] b = new byte[1024];
      int len = is.read(b);

      while(len != -1){
          os.write(b,0,len);
          len = is.read(b);
      }
    }
}
